﻿<?xml version="1.0" encoding="utf-8" ?>
<DbDataRequest connection="$ForumDBConnection$" type="$ForumDBType$" defaultFormatter="bizobj ForumGroup(forums(lastPost(createdBy)))">
  <SqlStatement hasResults="true">
	  SELECT fg.id, fg.name, fg.description,
	  f.id AS forumsid, f.name AS forumsname,
	  f.description AS forumsdescription, f.forumGroupId AS forumsforumGroupId,
	  f.numPost AS forumsnumPosts, f.numThread AS forumsnumThreads,
	  f.lastPostDate AS lastPostdateCreated, f.lastPostTitle as lastPosttitle,
	  f.lastPostById AS createdByid, f.lastPostByName AS createdByuserName,
	  tp.threadId AS lastPostthreadId
	  FROM ForumGroup fg
	  LEFT JOIN Forum f ON fg.id=f.forumGroupId
	  LEFT JOIN ForumThreads ft ON f.id=ft.forumId
	  LEFT JOIN ThreadPosts tp ON ft.id=tp.threadId AND f.lastPostDate=tp.dateCreated
	  WHERE fg.companyId=@companyId
  </SqlStatement>
  <Param name="companyId" type="UniqueIdentifier" />
</DbDataRequest>
